home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Examples / IconEdit / UIconEdit.h < prev   
Encoding:
Text File  |  1996-04-03  |  12.5 KB  |  522 lines  |  [TEXT/MPS ]

  1. // IconEdit.h
  2. // Copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #ifndef __UICONEDIT__
  5. #define __UICONEDIT__
  6.  
  7. // MacApp
  8.  
  9. #ifndef __UAPPLICATION__
  10. #include "UApplication.h"
  11. #endif
  12.  
  13. #ifndef __UCOMMAND__
  14. #include "UCommand.h"
  15. #endif
  16.  
  17. #ifndef __UFILEBASEDDOCUMENT__
  18. #include "UFileBasedDocument.h"
  19. #endif
  20.  
  21. #ifndef __UVIEW__
  22. #include "UView.h"
  23. #endif
  24.  
  25.  
  26. // Constants
  27. const OSType kSignature = 'ICED';                // Application signature
  28. const OSType kFileType = 'ICON';                // File-type for document files created by this application
  29.  
  30. // definitions for the custom apple event suite
  31. const OSType kAEIconEditClass = 'ICED';            // event class
  32.  
  33. const OSType kAEInvertID = 'INVT';                // event IDs
  34. const OSType kAEZoomInID = 'ZmIn';
  35. const OSType kAEZoomOutID = 'ZmOt';
  36. const OSType kAEDrawPoints = 'DrPt';
  37.  
  38. const AEKeyword keyPointList = 'kPtL';
  39. const AEKeyword keyErasePoints = 'kErs';
  40.  
  41. // Forward references
  42. class TIconBitMap;
  43. class TIconEditView;
  44.  
  45. // Classes
  46. // ====================================================================================
  47.  
  48. class TIconEditApplication : public TApplication
  49. {
  50.     MA_DECLARE_CLASS;
  51.  
  52. public:
  53.     virtual ~TIconEditApplication();
  54.     // Destructor
  55.  
  56.     virtual void IIconEditApplication();
  57.  
  58.     virtual TDocument* DoMakeDocument(CommandNumber itsCommandNumber,
  59.                                       TFile* itsFile);// Override
  60.  
  61.     virtual TView* MakeViewForAlienClipboard();    // Override
  62.     //  Makes a view of type TIconEditView for the Clipboard if the public desk
  63.     //    scrap contains data of type 'ICON'.  Otherwise it calls INHERITED
  64.     //    MakeViewForAlienClipboard. 
  65. };
  66.  
  67. // ====================================================================================
  68. //old class TIconDocument : public TDocument
  69.  
  70. class TIconDocument : public TFileBasedDocument    //new
  71. {
  72.     MA_DECLARE_CLASS;
  73.  
  74. public:
  75.     TIconDocument();
  76.     // Constructor
  77.  
  78.     void IIconDocument(TFile* itsDocument);
  79.  
  80.     virtual ~TIconDocument();
  81.  
  82.     virtual void DoInitialState();                // Override
  83.  
  84.     virtual void DoMakeViews(Boolean forPrinting);// Override
  85.  
  86.     virtual void DoMenuCommand(CommandNumber aCommandNumber);
  87.  
  88.     virtual void DoScriptCommand(CommandNumber aCommand,
  89.                                  TAppleEvent* message,
  90.                                  TAppleEvent* reply);// Override
  91.  
  92.     virtual void DoSetupMenus();                // Override
  93.  
  94.     virtual void DoNeedDiskSpace(TFile* itsDocument,
  95.                                  long& dataForkBytes,
  96.                                  long& rsrcForkBytes);// Override
  97.  
  98.     virtual void DoRead(TFile* itsDocument,
  99.                         Boolean forPrinting);    // Override
  100.  
  101.     virtual void DoWrite(TFile* itsDocument,
  102.                          Boolean makingCopy);    // Override
  103.  
  104.     virtual void InvertIcon();
  105.  
  106.     inline TIconEditView* GetIconView() const
  107.     { return fIconView; }
  108.  
  109.  
  110.     virtual void ClearIcon();
  111.  
  112.     virtual void SetIcon(TIconBitMap* newIcon);
  113.  
  114.     inline TIconBitMap* ReturnBitMap() const
  115.     { return fIconBitMap; }
  116.  
  117.     virtual void RedrawViews();
  118.  
  119.     virtual void GetSetPropertyInfo(DescType whichProperty,
  120.                                     CommandNumber& cmdNum,
  121.                                     Boolean& canUndo,
  122.                                     Boolean& causesChange,
  123.                                     TCommandHandler*& theContext);// Override
  124.  
  125.     virtual void SetObjectProperty(const CAEDesc& thePropertyValue,
  126.                                    DescType whichProperty);// Override
  127.  
  128.     virtual Boolean GetObjectProperty(CAEDesc& thePropertyValue,
  129.                                       DescType whichProperty,
  130.                                       const CAEDesc& desiredType); // Override
  131.  
  132.     inline CRGBColor GetIconColor() const
  133.     { return fColor; }
  134.  
  135.     virtual void SetIconColor(CRGBColor& newColor);
  136.  
  137. protected:
  138.     CRGBColor fColor;                            // color property of the document
  139.     TIconBitMap* fIconBitMap;                    // The icon's bit map
  140.     TIconEditView* fIconView;                    // a reference to the single view in this window
  141. };
  142.  
  143.  
  144. // ====================================================================================
  145.  
  146. class TIconEditView : public TView
  147. {
  148.     MA_DECLARE_CLASS;
  149.  
  150. public:
  151.     TIconEditView();
  152.     // Constructor
  153.  
  154.     virtual ~TIconEditView();
  155.     // Destructor
  156.  
  157.     virtual void IIconEditView(TDocument* itsDocument,
  158.                                TView* itsSuperView,
  159.                                const VPoint& itsLocation,
  160.                                short itsMagnification);
  161.  
  162.     virtual void DoPostCreate(TDocument* itsDocument);// Override
  163.  
  164.     virtual VRect CalcMinFrame();    // Override
  165.  
  166.     virtual Boolean ContainsClipType(ResType aType);// Override
  167.     //  Called when a view of this type is installed in the Clipboard.
  168.     //    Returns true if aType is kIconClipType (i.e. 'ICON'). 
  169.  
  170.     virtual void DoKeyEvent(TToolboxEvent* info);// Override
  171.     //  Treats the backspace the same as the Clear command. 
  172.  
  173.     virtual void DoMenuCommand(CommandNumber aCommandNumber);// Override
  174.  
  175.     virtual void DoMouseCommand(VPoint& theMouse,
  176.                                 TToolboxEvent* event,
  177.                                 CPoint hysteresis);// Override
  178.  
  179.     virtual void DoSetCursor(const VPoint& localPoint,
  180.                              RgnHandle cursorRegion);// Override
  181.  
  182.     virtual void DoSetupMenus();                // Override
  183.  
  184.     virtual void Draw(const VRect& area);        // Override
  185.  
  186.     virtual void DrawBit(VPoint theBit,
  187.                          Boolean turnBitOn,
  188.                          CRGBColor& drawingColor);
  189.  
  190.     Boolean PointToBit(const VPoint& thePoint,
  191.                                VPoint& iconBit);
  192.  
  193.     short GetMagnification() const
  194.     { return fMagnification; }
  195.  
  196.     virtual void SetMagnification(short magnification);
  197.  
  198.     virtual void WriteToDeskScrap();            // Override
  199.  
  200. protected:
  201.     TIconDocument* fIconDocument;                // Reference to the view's icon document.
  202.     short fMagnification;                        // No. of times to magnify the icon.
  203. };
  204.  
  205. // ====================================================================================
  206.  
  207. class TDrawPointsAppleEvent : public TAppleEvent
  208. {
  209.     MA_DECLARE_CLASS;
  210.  
  211. public:
  212.     TDrawPointsAppleEvent();
  213.  
  214.     virtual ~TDrawPointsAppleEvent();
  215.     // Destructor
  216.  
  217.     void IDrawPointsAppleEvent(MScriptableObject* itsDirectObject,
  218.                                TIconBitMap* iconBitMapModel,
  219.                                const Boolean turnBitsOn);
  220. };
  221.  
  222. // ====================================================================================
  223.  
  224. class TDrawPointsCommand : public TCommand
  225. {
  226.     MA_DECLARE_CLASS;
  227.  
  228. public:
  229.     TDrawPointsCommand();
  230.     // Constructor
  231.  
  232.     virtual ~TDrawPointsCommand();
  233.  
  234.     virtual void IDrawPointsCommand(TIconDocument* itsIconDocument,
  235.                                     TAppleEvent* theAppleEvent);
  236.  
  237.     virtual void DoIt();                        // Override
  238.  
  239.     virtual void RedoIt();                        // Override
  240.  
  241.     virtual void UndoIt();                        // Override
  242.  
  243. protected:
  244.     TIconBitMap* fSavedBitMap;
  245.     TIconDocument* fIconDocument;                // The document affected by this command.
  246.     TDynamicArray* fPointList;                    // list of points to set or unset
  247.     Boolean fErasePoints;
  248. };
  249.  
  250. // ====================================================================================
  251.  
  252. class TSetColorCommand : public TCommand
  253. {
  254.     MA_DECLARE_CLASS;
  255.  
  256. public:
  257.     TSetColorCommand();
  258.     // Constructor
  259.  
  260.     virtual ~TSetColorCommand();
  261.     // Destructor
  262.  
  263.     virtual void ISetColorCommand(TIconDocument* itsIconDocument,
  264.                                   CRGBColor& newColor);
  265.  
  266.     virtual void DoIt();                        // Override
  267.  
  268.     virtual void RedoIt();                        // Override
  269.  
  270.     virtual void UndoIt();                        // Override
  271.  
  272. protected:
  273.     CRGBColor fOldColor;
  274.     CRGBColor fNewColor;
  275. };
  276.  
  277.  
  278. // ====================================================================================
  279.  
  280. class TInvertCommand : public TCommand
  281. {
  282.     MA_DECLARE_CLASS;
  283.  
  284. public:
  285.     TInvertCommand();
  286.     // Constructor
  287.  
  288.     virtual ~TInvertCommand();
  289.     // Destructor
  290.  
  291.     virtual void IInvertCommand(TIconDocument* itsIconDocument);
  292.  
  293.     virtual TAppleEvent* MakeAppleEvent();
  294.  
  295.  
  296.     virtual void DoIt();                        // Override
  297.  
  298.     virtual void RedoIt();                        // Override
  299.  
  300.     virtual void UndoIt();                        // Override
  301.  
  302. protected:
  303.     TIconDocument* fIconDocument;                // The document affected by this command.
  304. };
  305.  
  306.  
  307. // ====================================================================================
  308.  
  309. class TIconDrawCommand : public TTracker
  310. {
  311.     MA_DECLARE_CLASS;
  312.  
  313. public:
  314.     TIconDrawCommand();
  315.     // Constructor
  316.  
  317.     virtual ~TIconDrawCommand();
  318.  
  319.     virtual void IIconDrawCommand(TIconEditView* itsIconEditView,
  320.                                   TIconDocument* itsIconDocument,
  321.                                   VPoint& theMouse);
  322.  
  323.     virtual void DoIt();                        // Override
  324.     //  Sets the fIconDocument's icon bitmap to that of fIconBitMap by calling
  325.     //    the document's SetIcon method. Validates the edit view to avoid
  326.     //    flashing.     
  327.  
  328.     virtual void RedoIt();                        // Override
  329.  
  330.     virtual void TrackConstrain(TrackPhase aTrackPhase,
  331.                                 const VPoint& anchorPoint,
  332.                                 const VPoint& previousPoint,
  333.                                 VPoint& nextPoint,
  334.                                 Boolean mouseDidMove);
  335.  
  336.     virtual void TrackFeedback(TrackPhase aTrackPhase,
  337.                                const VPoint& anchorPoint,
  338.                                const VPoint& previousPoint,
  339.                                const VPoint& nextPoint,
  340.                                Boolean mouseDidMove,
  341.                                Boolean turnItOn);
  342.  
  343.     virtual TTracker* TrackMouse(TrackPhase aTrackPhase,
  344.                                  VPoint& anchorPoint,
  345.                                  VPoint& previousPoint,
  346.                                  VPoint& nextPoint,
  347.                                  Boolean mouseDidMove);
  348.  
  349.     virtual void UndoIt();                        // Override
  350.     //  Sets the fIconDocument's icon bitmap to that of fOriginalIcon by calling
  351.     //    the document's SetIcon method. 
  352.  
  353. protected:
  354.     CRGBColor fColor;                            // drawing color (property of fDocument)
  355.     TIconDocument* fIconDocument;                // The document affected by this command.
  356.     TIconEditView* fIconEditView;                // The view in which this command draws.
  357.     TIconBitMap* fIconBitMap;                    // The icon in which drawing takes place.
  358.     TIconBitMap* fIconBitMapModel;                // Model used to generate apple events
  359.     TIconBitMap* fOriginalIcon;                    // A copy of the original icon.
  360.     Boolean fTurnBitsOn;                        // Whether to draw bits black or white.
  361. };
  362.  
  363.  
  364. // ====================================================================================
  365.  
  366. class TIconEditCommand : public TCommand
  367. {
  368.     MA_DECLARE_CLASS;
  369.  
  370. public:
  371.     TIconEditCommand();
  372.     // Constructor
  373.  
  374.     virtual ~TIconEditCommand();
  375.  
  376.     virtual void IIconEditCommand(CommandNumber itsCommandNumber,
  377.                                   TIconEditView* itsIconEditView,
  378.                                   TIconDocument* itsIconDocument);
  379.     virtual void DoIt();                        // Override
  380.  
  381.     virtual void RedoIt();                        // Override
  382.  
  383.     virtual void UndoIt();                        // Override
  384.  
  385. protected:
  386.     TIconDocument* fIconDocument;                // The document affected by this command.
  387.     TIconEditView* fIconEditView;                // The view in which this command draws.
  388.     TIconBitMap* fSavedBitMap;                    // Saved state for undo/redo
  389. };
  390.  
  391.  
  392. // ====================================================================================
  393.  
  394. class TIconPasteCommand : public TCommand
  395. {
  396.     MA_DECLARE_CLASS;
  397.  
  398. public:
  399.     TIconPasteCommand();
  400.     // Constructor
  401.  
  402.     virtual ~TIconPasteCommand();
  403.  
  404.     virtual void IIconPasteCommand(TIconEditView* itsIconEditView,
  405.                                    TIconDocument* itsIconDocument);
  406.     virtual void DoIt();                        // Override
  407.  
  408.     virtual void UndoIt();                        // Override
  409.  
  410. protected:
  411.     TIconDocument* fIconDocument;                // The document affected by this command.
  412.     TIconEditView* fIconEditView;                // The view in which this command draws.
  413.     TIconBitMap* fSavedIcon;                    // Temporary saved icon
  414. };
  415.  
  416.  
  417. // ====================================================================================
  418.  
  419. class TIconBitMap : public TObject
  420. {
  421.     MA_DECLARE_CLASS;
  422.  
  423. public:
  424.     TIconBitMap();
  425.     // Constructor
  426.  
  427.     virtual ~TIconBitMap();
  428.  
  429.     virtual void IIconBitMap();
  430.  
  431.     virtual void SetIconBitMap(Handle theBitMap);
  432.  
  433.     virtual void ReadFrom(TStream* aStream);    // Override
  434.  
  435.     virtual void WriteTo(TStream* aStream);        // Override
  436.  
  437.     virtual void LoadFromScrap();
  438.  
  439.     virtual void WriteToScrap();
  440.  
  441.     virtual TIconBitMap* Copy();
  442.  
  443.     virtual void CopyDataTo(TIconBitMap* anIcon);
  444.  
  445.     virtual void Clear();
  446.  
  447.     virtual void Invert();
  448.  
  449.     virtual void Draw(const CRect& area,
  450.                       const CRGBColor& drawingColor);//not Override!
  451.  
  452.     virtual Boolean GetBit(VPoint iconBit);
  453.  
  454.     virtual void SetBit(VPoint iconBit,
  455.                         Boolean turnBitOn);
  456.  
  457.     virtual void IconBitToByteBit(VPoint iconBit,
  458.                                   short& byte,
  459.                                   short& bit);
  460.  
  461. protected:
  462.     Handle fDataHandle;                            // Handle to the icon's data.
  463. };
  464.  
  465.  
  466. // ====================================================================================
  467. class TZoomOutCommand : public TCommand
  468. {
  469.     MA_DECLARE_CLASS;
  470.  
  471. public:
  472.     TZoomOutCommand();
  473.     // Constructor
  474.  
  475.     virtual ~TZoomOutCommand();
  476.     // Destructor
  477.  
  478.     virtual void IZoomOutCommand(TIconDocument* itsIconDocument);//, TAppleEvent* theAppleEvent);
  479.  
  480.     virtual void DoIt();                        // Override
  481.  
  482.     virtual void RedoIt();                        // Override
  483.  
  484.     virtual void UndoIt();                        // Override
  485.  
  486.     virtual TAppleEvent* MakeAppleEvent();
  487.  
  488. public:
  489.     TIconDocument* fIconDocument;                // The document affected by this command.
  490. };
  491.  
  492.  
  493. // ====================================================================================
  494. class TZoomInCommand : public TCommand
  495. {
  496.     MA_DECLARE_CLASS;
  497.  
  498. public:
  499.     TZoomInCommand();
  500.     // Constructor
  501.  
  502.     virtual ~TZoomInCommand();
  503.     // Destructor
  504.  
  505.     virtual void IZoomInCommand(TIconDocument* itsIconDocument);//, TAppleEvent* theAppleEvent);
  506.  
  507.     virtual void DoIt();                        // Override
  508.  
  509.     virtual void RedoIt();                        // Override
  510.  
  511.     virtual void UndoIt();                        // Override
  512.  
  513.     virtual TAppleEvent* MakeAppleEvent();
  514.  
  515. public:
  516.     TIconDocument* fIconDocument;                // The document affected by this command.
  517. };
  518.  
  519. #endif
  520.  
  521.  
  522.